package test.day01;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class LongestSubstring {
	public static void main(String[] args) {
		String str = "abcabcdfrbb";
		System.out.println(longestSubstring(str));
		str = "pwwkew";
		System.out.println(longestSubstring(str));
	}

	public static String longestSubstring(String str) {
		int oldNum = 0, newNum = 1;
		Map<Integer, String> listMap = new HashMap<>();
		for (int i = 0; i < str.length(); i++) {
			String tmpStr = "";
			for (int j = i; j < str.length(); j++) {
				char c = str.charAt(j);
				if (!tmpStr.contains(c + "")) {
					tmpStr += c;
					newNum = tmpStr.length();
					if (oldNum < newNum) {
						oldNum = newNum;
						listMap.put(oldNum, tmpStr);
					}
				} else {
					break;
				}
			}
		}
		return listMap.get(oldNum);
	}
}
